package com.gift.recommendation.modules.admin.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.Base.PageData;
import com.gift.recommendation.config.TokenPass;
import com.gift.recommendation.modules.admin.biz.NoticeImpl;
import com.gift.recommendation.modules.admin.dto.NoticeListReq;
import com.gift.recommendation.modules.admin.dto.NoticeReleaseAddReq;
import com.gift.recommendation.modules.admin.dto.NoticeRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/1/15
 */
@RestController
@RequestMapping("/gift/notice")
@Api(tags = "通知")
@Validated
public class NoticeController {

    @Autowired
    private NoticeImpl notice;

    @ApiOperation(value = "添加通知")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public BaseResponse noticeAdd(@RequestBody NoticeReleaseAddReq req){
        notice.addNotice(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "修改通知")
    @RequestMapping(path = "/update",method = RequestMethod.POST)
    public BaseResponse noticeUpdate(@RequestBody NoticeReleaseAddReq req){
        notice.noticeUpdate(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "删除通知")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public BaseResponse noticeDelete(@RequestParam Long id){
        notice.deleteNotice(id);
        return BaseResponse.success();
    };

    @ApiOperation(value = "上线通知")
    @RequestMapping(path = "/release",method = RequestMethod.POST)
    public BaseResponse releaseNotice(@RequestParam Long id){
        notice.releaseNotice(id);
        return BaseResponse.success();
    };

    @ApiOperation(value = "下线通知")
    @RequestMapping(path = "/offline-release",method = RequestMethod.POST)
    public BaseResponse offlineReleaseNotice(@RequestParam Long id){
        notice.offlineReleaseNotice(id);
        return BaseResponse.success();
    };

    @ApiOperation(value = "检查通知")
    @RequestMapping(path = "/check",method = RequestMethod.GET)
    @TokenPass
    public BaseResponse checkNotice(){
        NoticeRsp noticeRsp = notice.checkNotice();
        return BaseResponse.success(noticeRsp);
    };

    @ApiOperation(value = "查看通知列表")
    @RequestMapping(path = "/list",method = RequestMethod.POST)
    public BaseResponse<PageData<NoticeRsp>> listNotice(@RequestBody NoticeListReq listReq){
        PageData<NoticeRsp> result = notice.list(listReq);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "根据主键id搜索通知")
    @RequestMapping(path = "/get",method = RequestMethod.GET)
    public BaseResponse releaseSearchById(@RequestParam Long id){
        NoticeRsp result = notice.releaseSearchById(id);
        return BaseResponse.success(result);
    };
}
